<?php
	$title='Fitness forum - view topic';
	$description='Fitness forum view topic';
	$keywords='fitness, muscles, training, supplements, diet, nutririon, forum';
?>
<?php include('fns_db_forum.php'); ?>
<?php include('forum_utils.php'); ?>
<?php include('../views/layouts/_header.php'); ?>
<?php include('../views/layouts/_left.php'); ?>

<?php
if (isset($_GET['topicID'])) {$id = $_GET['topicID'];}

$result = all_threads_for_topic($id);

if ($result == 0)
{
	echo "<b>Error: ";
	#echo mysqli_error($cxn)."</b>";
}
else
{
	echo "<table width=\"100%\"
	class=\"forumline \"cellpadding=\"4\"";
	echo " cellspacing=\"2\" border=\"0\" align=\"center\">";
	echo "<tbody>";
	echo '
	<tr class="heading2">
	<th  height="25"
	nowrap="nowrap">Subject</th>
	<th nowrap="nowrap"
	width="50">Replies</th>
	<th nowrap="nowrap"
	width="50">Author</th>
	<th nowrap="nowrap">Last Post</th>
	</tr>';

	for( $i = 0; $i < mysqli_num_rows( $result ); $i++ )
	{
		$thread = mysqli_fetch_assoc( $result );
		echo "<tr>\n";
		echo '<td class="heading3">'; #39
			echo '<a href="view_thread.php?threadID='.
			$thread['id'] . '">';
			echo $thread['subject'];
			echo '</a>';
			if(checkIfAdmin()){
				echo '<br/><a href="delete.php?target=thread&id=' .$thread['id'] . '">delete</a>';
			}
		echo " </td>\n";
		AddField( $thread, "replies", "threadFiller" );
		AddField( $thread, "author", "threadFiller" );
		AddField( $thread, "last_post", "threadFiller" );
		echo "</tr>\n";
	}
	echo "</tbody></table>";
	echo '<b><a href="post_message.php?topicID='.
	$_GET['topicID']. '">';
	echo "Start a new thread</a></b>";
}
?>

<?php include('../views/layouts/_footer.php'); ?>
